package com.lzh.thinkpet.quartz;

import com.lzh.thinkpet.mail.SendJunkMailService;
import com.lzh.thinkpet.model.Admin;
import com.lzh.thinkpet.service.AdminService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lzh
 * @date 2019/1/22 - 10:33
 */
@Component
@Configurable
@EnableScheduling
public class SendMailQuartz {
    /**
     * 日志对象
     */
    private static final Logger logger = LogManager.getLogger(SendMailQuartz.class);

    /**
     * 注入邮件发送服务
     */
    @Resource
    private SendJunkMailService sendJunkMailService;

    @Autowired
    private AdminService adminService;

    /**
     * 0 0 10,12,16 * * ? 每天上午10点，12点,下午4点
     */
    @Scheduled(cron = "0 0 10,11,16 * * ?")
    public void reportCurrentByCron(){

        List<Admin> adminList = adminService.findAllAdmin();
        if (adminList == null || adminList.size() <= 0){
            return;
        }
        //发送邮件
        sendJunkMailService.sendJunkMail(adminList,"javaMail测试","1131201834@qq.com","！！！这是一次程序测试");
        logger.info("定时器 运行了！！！");

    }




}
